#include <bits/stdc++.h>
// 2025/02/03
// tag: 
// Author: Zhang Muen
using namespace std;

int R, C, A, B;
int64_t cake[501][501];

void init(){
    for (int i = 1; i <= R; i++)
        for (int j = 1; j <= C; j++)
            cake[i][j] += cake[i - 1][j] + cake[i][j - 1] - cake[i - 1][j - 1];
}

int64_t presum(int x1, int y1, int x2, int y2)
{
    return cake[x1 - 1][y1 - 1] + cake[x2][y2] - cake[x1 - 1][y2] - cake[x2][y1 - 1];
}

bool checkline(int x, int y, int k){
    int l = 1, r = 1, cnt = 0;
    while (cnt < B && r <= C){
        if (presum(x, l, y, r) >= k)
            l = r + 1, r = l, cnt++;
        else
            r++;
    }
    return cnt == B;
}

bool check(int k){
    int l = 1, r = 1, cnt = 0;
    while (cnt < A && r <= R) {
        if (checkline(l, r, k))
            l = r + 1, r = l, cnt++;
        else
            r++;
    }
    return cnt == A;
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> R >> C >> A >> B;
    for (int i = 1; i <= R; i++)
        for (int j = 1; j <= C; j++)
            cin >> cake[i][j];
    init();
    int64_t l = 1, r = 1e9;
    while (l <= r){
        int64_t mid = (l + r) >> 1;
        if (check(mid))
            l = mid + 1;
        else
            r = mid - 1;
    }
    cout << r;
    return 0;
}